package android.team.app.utility;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.team.app.R;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class SmartDialogUtility  extends Dialog{
	
	private TextView tvTitle, tvMessage;
	private ImageView imgIcon, imgPositive, imgNegative;
	
	private View.OnClickListener defaultDismiss = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			dismiss();
		}
	};
	
	
	public SmartDialogUtility(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	private DialogInterface.OnDismissListener positiveDismiss, nagativeDismiss;
	
	private View.OnClickListener positiveButtonClick = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			setOnDismissListener(positiveDismiss);
			dismiss();
		}
	};
	
	private View.OnClickListener nagativeButtonClick = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			setOnDismissListener(nagativeDismiss);
			dismiss();
		}
	};
	
	public SmartDialogUtility(Context context, int title, int message, int iconPositiveButton){
		super(context);
		
		//bo title default cua dialog
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.positive_custom_dialog);
		
		tvTitle = (TextView)findViewById(R.id.titleDialog);
		tvTitle.setText(context.getString(title));
		
		tvMessage = (TextView)findViewById(R.id.messageDialog);
		tvMessage.setText(context.getString(message));
		
		ImageView positiveButton1 = (ImageView)findViewById(R.id.btPositionDialog);
		positiveButton1.setBackgroundResource(iconPositiveButton);
		positiveButton1.setOnClickListener(defaultDismiss);
	}
	
	//----------Standard Dialog-----------//
	public static void showStandardDialog(
			Context context, 
			String title, 
			int icon, 
			String message, 
			String bt1Name, OnClickListener onclickbt1,
			String bt2Name, OnClickListener onclickbt2,
			String bt3Name, OnClickListener onclickbt3){
		
		//step1: dinh nghia dialog
		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		
		//step2: add attribute for header dialog
		dialog.setIcon(icon);
		dialog.setTitle(title);
		
		//step3: add attribute for body dialog
		dialog.setMessage(message);
		
		if(bt1Name!=null){
			dialog.setPositiveButton(bt1Name, onclickbt1);
		}
		if(bt2Name!=null){
			dialog.setNegativeButton(bt2Name, onclickbt2);
		}
		if(bt3Name!=null){
			dialog.setNeutralButton(bt3Name, onclickbt3);
		}
		
		//step4: show Dialog
		dialog.show();
	}
	
	
	
	//----------Custom Dialog-----------//
	

}
